//
// Created by Zhangwj on 2023/9/25.
//

#include "VarDeclNode.h"

std::unique_ptr<VarDeclNode> VarDeclNode::VarDeclParser(Parser &parser) {
    //VarDecl → BType VarDef { ',' VarDef } ';'
    std::unique_ptr<VarDeclNode> varDeclNode = std::make_unique<VarDeclNode>();
    varDeclNode->BType = BTypeNode::BTypeParser(parser);
    varDeclNode->VarDefs.push_back(VarDefNode::VarDefParser(parser));
    while (parser.getLexType(0) == LexType::COMMA) {
        parser.next();
        varDeclNode->VarDefs.push_back(VarDefNode::VarDefParser(parser));
    }
    if (parser.getLexType(0) == LexType::SEMICN) {
        parser.next();
    }
    return varDeclNode;
}
